package fiuba.td.fabrica.view.frames;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Observer;

import javax.swing.JDialog;
import javax.swing.JPanel;

import fiuba.td.fabrica.controller.Controller;

public abstract class VentanaJuegoTemplate extends JDialog {

	private Container contenedor;
	private ObserverJPanel surJPanel;
	private JPanel esteJPanel;
	private ObserverJPanel oesteJPanel;
	private JPanel centroJPanel;
	private JPanel norteJPanel;
	
	// Controller
	private Controller controller;
		
	public VentanaJuegoTemplate(int width, int height, boolean isVisible, Observer observer) {
		this.setResizable(false);
		
		this.setSize(width, height);
		
		this.controller = Controller.getInstance();
		
		this.contenedor = this.getContentPane();
		this.contenedor.setLayout(new BorderLayout());
		
		// Agrego los paneles
		this.addOesteJPanel (width, height, observer);
		this.addSurJPanel 	(width, height, observer);
		this.addEsteJPanel 	(width, height, observer);
		this.addNorteJPanel (width, height, observer);
		this.addCentroJPanel(width, height, observer);

		// Se obtienen las dimensiones en pixels de la pantalla.
        Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
        
        // Se obtienen las dimensiones en pixels de la ventana.
        Dimension ventana = this.getSize();
        
        // Una cuenta para situar la ventana en el centro de la pantalla.
        this.setLocation(
            (pantalla.width - ventana.width) / 2,
            (pantalla.height - ventana.height) / 2);
        
        // Se visualiza la ventana.
        this.setVisible(isVisible);
        
        this.addWindowListener(observer);
	}

	public abstract void addWindowListener 	(Observer observer);
	public abstract void addConcreteSurJPanel	(Dimension dimension, Observer observer);
	public abstract void addConcreteNorteJPanel (Dimension dimension, Observer observer);
	public abstract void addConcreteOesteJPanel (Dimension dimension, Observer observer);
	public abstract void addConcreteEsteJPanel	(Dimension dimension, Observer observer);
	public abstract void addConcreteCentroJPanel(Dimension dimension, Observer observer);
	
	public void addSurJPanel(int width, int height, Observer observer){
		this.addConcreteSurJPanel(new Dimension (width*70/100, height*10/100), observer);
		this.getContenedor().add(this.getSurJPanel(),BorderLayout.SOUTH);
	}
	public void addNorteJPanel(int width, int height, Observer observer){
		this.addConcreteNorteJPanel(new Dimension(width*70/100, height*10/100),observer);
		this.getContenedor().add(this.getNorteJPanel(),BorderLayout.NORTH);
	}
	public void addEsteJPanel(int width, int height, Observer observer){
		this.addConcreteEsteJPanel(new Dimension(width*15/100, height),observer);
		this.getContenedor().add(this.getEsteJPanel(),BorderLayout.EAST);
	}
	public void addOesteJPanel(int width, int height, Observer observer){
		this.addConcreteOesteJPanel(new Dimension(width*15/100, height),observer);
		this.getContenedor().add(this.getOesteJPanel(),BorderLayout.WEST);
	}
	public void addCentroJPanel(int width, int height, Observer observer){
		this.addConcreteCentroJPanel(new Dimension(width*70/100, height*80/100),observer);
		this.getContenedor().add(this.getCentroJPanel(),BorderLayout.CENTER);
	}

	public Container getContenedor() {
		return contenedor;
	}

	public void setContenedor(Container contenedor) {
		this.contenedor = contenedor;
	}

	public ObserverJPanel getSurJPanel() {
		return surJPanel;
	}

	public void setSurJPanel(ObserverJPanel surJPanel) {
		this.surJPanel = surJPanel;
	}

	public JPanel getEsteJPanel() {
		return esteJPanel;
	}

	public void setEsteJPanel(JPanel esteJPanel) {
		this.esteJPanel = esteJPanel;
	}

	public ObserverJPanel getOesteJPanel() {
		return oesteJPanel;
	}

	public void setOesteJPanel(ObserverJPanel oesteJPanel) {
		this.oesteJPanel = oesteJPanel;
	}

	public JPanel getCentroJPanel() {
		return centroJPanel;
	}

	public void setCentroJPanel(JPanel centroJPanel) {
		this.centroJPanel = centroJPanel;
	}

	public JPanel getNorteJPanel() {
		return norteJPanel;
	}

	public void setNorteJPanel(JPanel norteJPanel) {
		this.norteJPanel = norteJPanel;
	}

	public Controller getController() {
		return controller;
	}

	public void setController(Controller controller) {
		this.controller = controller;
	}
	 

}
